package demo1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Test1 {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(11);
        list.add(3);
        list.add(2);
        //ArrayList<Integer> arrayList = new ArrayList<>(list);
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0);
        arrayList.add(5);
        arrayList.add(6);

       // System.out.println(arrayList.get(0));
        arrayList.add(new Integer(23));
        arrayList.add(1,89);
        arrayList.addAll(1,list);
        System.out.println(arrayList);

        //删除后数会返回一个E类型的数
        Integer a = arrayList.remove(1);
        System.out.println(a);

        arrayList.remove(new Integer(6));
        System.out.println(arrayList);
        int c = arrayList.indexOf(new Integer(23));
        System.out.println(c);

        List<Integer> sub = arrayList.subList(2,5);
        System.out.println(sub.toString());

        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i) + " ");
        }
        System.out.println();
        System.out.println("------------------------");

        for (Integer x : arrayList) {
            System.out.print(x+" ");
        }
        System.out.println();
        //迭代器
        Iterator<Integer> it = arrayList.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }

    }
}
